#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>

const QString strScrollCation = QString("一盏青灯伴古佛，半为修行半入魔。");

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_pLabel = ui->label;
    QTimer *pTimer = new QTimer(this);
    connect(pTimer,  SIGNAL(timeout()),  this,  SLOT(scrollCaption()));
    // 定时200毫秒
    pTimer->start(200);
}

void MainWindow::scrollCaption()
{
    static int nPos = 0;

    // 当截取的位置比字符串长时，从头开始
    if (nPos > strScrollCation.length())
        nPos = 0;

    m_pLabel->setText(strScrollCation.mid(nPos));
    nPos++;
}

MainWindow::~MainWindow()
{
    delete ui;
}
